package cn.ang.app.service.impl;

import cn.ang.app.mapper.AppInfoMapper;
import cn.ang.app.pojo.AppInfo;
import cn.ang.app.pojo.extend.AppInfoExt;
import cn.ang.app.service.AppInfoService;
import cn.ang.app.tools.Pagelimit;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppInfoServiceImpl implements AppInfoService {

    @Resource
    private AppInfoMapper appInfoMapper;

    @Override
    public Pagelimit<AppInfoExt> showAppInfo(AppInfoExt appInfo, Integer pageNo, Integer pageSize) {
        int count = appInfoMapper.selectAppInfosCount(appInfo);

        Pagelimit<AppInfoExt> pagelimit= new Pagelimit<>(pageNo,pageSize,count);

        List<AppInfoExt> appInfoExts = appInfoMapper.selectAppInfos(appInfo, (pageNo - 1) * pageSize, pageSize);
        for (AppInfoExt appInfoExt : appInfoExts) {
            if( appInfoExt.getNewVersionName() == null) {
                appInfoExt.setNewVersionName("暂无");
            }
        }

        pagelimit.setList(appInfoExts);
        pagelimit.setObject(appInfo);

        return pagelimit;
    }

    @Override
    public boolean deleteAppInfo(Long id) {
        int row = appInfoMapper.deleteByPrimaryKey(id);
        return row>0;
    }

    @Override
    public boolean insertAppInfo(AppInfo appInfo) {
        int row = appInfoMapper.insertSelective(appInfo);
        return row>0;
    }
}
